﻿namespace Sgr.Serialization
{
    /// <summary>
    /// 内部共用逻辑
    /// </summary>
    internal static class UtcDateTimeConverterInternal
    {
        /// <summary>
        /// 处理 Unspecified：根据 assumeLocal 策略决定是否先视为 Local 再转 UTC，或直接标记为 UTC。
        /// </summary>
        internal static DateTime HandleUnspecified(DateTime value, bool assumeLocal)
        {
#if DEBUG
            System.Diagnostics.Debug.WriteLine(
                $"[UtcDateTimeConverter] Unspecified DateTime: {value:o}, assumeLocal={assumeLocal}, 处理方式={(assumeLocal ? "Local->UTC" : "SpecifyKind(UTC)")}");
#endif
            if (assumeLocal)
            {
                // 视为本地 -> 转 UTC
                var local = DateTime.SpecifyKind(value, DateTimeKind.Local);
                return local.ToUniversalTime();
            }

            // 视为已经是 UTC 绝对时刻，只缺少 Kind
            return DateTime.SpecifyKind(value, DateTimeKind.Utc);
        }
    }
}